//
//  SecodViewController.m
//  runtimeDemo
//
//  Created by admin on 2018/2/8.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "SecodViewController.h"
#import "UIScreen+screenSize.h"

@interface SecodViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) NSDate *birthday;

@end

@implementation SecodViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
}


- (BOOL)isEqual:(id)object {
    // ==运算符判断是否是同一对象，因为同一对象必然相同
    if (self == object) {
        return YES;
    }
    // 判断是否是同一类型，这样不仅可以提高判断的效率，还可以避免隐式类型转换带来的潜在风险
    if (![object isKindOfClass:[SecodViewController class]]) {
        return NO;
    }
    
    return [self isEqualToPerson:(SecodViewController *)object];
}

- (BOOL)isEqualToPerson:(SecodViewController *)person {
    if (!person) {
        return NO;
    }
    // 对各个属性分别使用默认判等方法进行判断
    BOOL haveEqualNames = (!self.name && !person.name) || [self.name isEqualToString:person.name];
    BOOL haveEqualBirthdays = (!self.birthday && !person.birthday) || [self.birthday isEqualToDate:person.birthday];
    return haveEqualNames && haveEqualBirthdays;
}

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        _layout.itemSize = CGSizeMake(57, 60);
        _layout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5);
        _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen screenWidth], [UIScreen screenHeight] - 100) collectionViewLayout:_layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    }
    return _collectionView;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 98;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

// 设置item是否可以移动
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}



@end
